/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <iostream>
#include "assembly-ins.h"

namespace libabckit {

% additional_deprecated_opcodes = ["JNSTRICTEQUNDEFINED",
%                                 "JSTRICTEQUNDEFINED",
%                                 "JNEUNDEFINED",
%                                 "JEQUNDEFINED",
%                                 "JNSTRICTEQNULL",
%                                 "JSTRICTEQNULL",
%                                 "JNENULL",
%                                 "JEQNULL",
%                                 "JNSTRICTEQZ",
%                                 "JSTRICTEQZ",
%                                 "STTOGLOBALRECORD",
%                                 "STCONSTTOGLOBALRECORD",
%                                 "CREATEREGEXPWITHLITERAL",
%                                 "CLOSEITERATOR"]

% replaced_opcodes = ["JNSTRICTEQ",
%                    "JSTRICTEQ",
%                    "JNE",
%                    "JEQ"]

% skipped_opcodes = additional_deprecated_opcodes + replaced_opcodes

// NOLINTNEXTLINE(readability-function-size)
inline panda::pandasm::Opcode OpcFromName(const std::string &name) {
% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
%  insn = group.first
%   if !(insn.opcode.upcase.include? "DEPRECATED_") && !(skipped_opcodes.include? insn.mnemonic.upcase)
    if (name == "<%= insn.mnemonic.gsub('.', '_') %>") {
        return panda::pandasm::Opcode::<%= insn.asm_token%>;
    }
%   end
% end
% Panda::pseudo_instructions.each do |insn|
    if (name == "<%= insn.opcode.gsub('.', '_') %>") {
            return panda::pandasm::Opcode::<%= insn.opcode %>;
    }
% end
    if (name == "INVALID") {
        return panda::pandasm::Opcode::INVALID;
    }
    UNREACHABLE();
}

} // namespace libabckit
